﻿using Sunny.UI;
using System.Drawing;
using System.Windows.Forms;

namespace CoreShop.App
{
    public partial class UIMenuItemSeparator : UIUserControl
    {
        public UIMenuItemSeparator()
        {
            InitializeComponent();
            this.Height = 20;
        }

        public UIMenuItemSeparator(string text, int height = 40,int Width = 260)
        {
            InitializeComponent();
            if (Width < text.Length) Width = text.Length;
            this.Text = text;
            this.Height = height;
            this.Width = Width;
        }

        private void UIMenuItemSeparator_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            if (!OtherMode)
            {
                if (Text.IsValid())
                {
                    Size sz = TextRenderer.MeasureText(Text, Font);
                    e.Graphics.DrawString(Text, Font, ForeColor, new Rectangle(30, 0, Width, Height), ContentAlignment.MiddleLeft);
                    e.Graphics.DrawLine(ForeColor, new Point(30 + sz.Width + 3, Height / 2), new Point(Width, Height / 2));
                }
                else
                {
                    e.Graphics.DrawLine(ForeColor, new Point(0, Height / 2), new Point(Width, Height / 2));
                }
            }
            else
            {
                e.Graphics.DrawString(Text, Font, ForeColor, new Rectangle(0, 0, Width, Height), ContentAlignment.MiddleLeft);
            }
        }

        public bool OtherMode
        {
            get; set;
        } = false;

        public void SetOtherMode()
        {
            OtherMode = true;
            ForeColor = Color.OrangeRed;
            Font = new Font("微软雅黑", 12);
            //Width = 260;
            Invalidate();
        }
    }
}
